package com.mx.recycleview.utils

import android.content.Context
import android.view.View
import com.mx.recycleview.R
import kotlin.math.roundToInt

fun Context.dp2px(dp: Float): Int {
    return (dp * this.resources.displayMetrics.density + 0.5f).roundToInt()
}

fun Any.Log(msg: Any) {
    println(this::class.java.simpleName + " : " + msg.toString())
}

/**
 * 获取View的实际位置
 */
fun View.getPosition(): Int? {
    val tag = this.getTag(R.id.tagChildTag)
    return if (tag != null) {
        tag as Int
    } else {
        null
    }
}

/**
 * 设置View的实际位置
 */
fun View.setPosition(position: Int?) {
    this.setTag(R.id.tagChildTag, position)
}